package edu.bu.cs673b1s1p3.googlemaps;

import java.awt.BorderLayout;

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;


public class DisplayBusOnRoute extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2338006891590759002L;
	private static Action enterAction;
	private String busLat = "42.3505999";
	private String busLong = "-71.10985";
	private String mapAddress = "http://maps.googleapis.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:S|" + busLat + "," + busLong + "&sensor=true";
	//private URL mapURL = new URL("http://www.google.com");
	private BufferedImage myPicture = null;

	public static void main(String[] args) {
		
		DisplayBusOnRoute frame = new DisplayBusOnRoute();
		frame.pack();
		frame.setVisible(true);
		
		
	}
	
	public DisplayBusOnRoute(){
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
		//Panels 
		JPanel topPanel = new JPanel(new FlowLayout());
		//JPanel left = new JPanel(new BorderLayout());
		
		//Labels
		JLabel latLabel = new JLabel("Latitude: ");
		JLabel longLabel = new JLabel("Longitude: ");
		
		//Text Boxes
		JTextField latitudeInput = new JTextField(10);
		JTextField longitudeInput = new JTextField(10);
		
		//Google Map
		/*
		try {
			//myPicture = ImageIO.read(mapURL);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
		
		//Add to Layout
		topPanel.add(latLabel);
		topPanel.add(latitudeInput);
		topPanel.add(longLabel);
		topPanel.add(longitudeInput);
		getContentPane().add(topPanel,BorderLayout.NORTH);
		getContentPane().add(picLabel,BorderLayout.CENTER);
		
		//EVENTS
		
		// defines an AbstractAction item that will program the action to occur
        // when the enter key is pressed
        enterAction = new EnterAction();
        
        // the following two lines do the magic of key binding. the first line
        // gets the dataField's InputMap and pairs the "ENTER" key to the
        // action "doEnterAction" . . .
        latitudeInput.getInputMap().put( KeyStroke.getKeyStroke( "ENTER" ), "doEnterAction" );
        
        // . . . then this line pairs the AbstractAction enterAction to the
        // action "doEnterAction"
        latitudeInput.getActionMap().put( "doEnterAction", enterAction );
		
		
	}
	
	// class EnterAction is an AbstractAction that defines what will occur
    // when the enter key is pressed. 
    static class EnterAction extends AbstractAction
    {
		private static final long serialVersionUID = 464793971843044185L;

		public void actionPerformed( ActionEvent tf )
        {
            // provides feedback to the console to show that the enter key has
            // been pressed
            System.out.println( "The Enter key has been pressed." );
            
            // pressing the enter key then 'presses' the enter button by calling
            // the button's doClick() method
            System.out.println("test");
            
        } // end method actionPerformed()
        
    } // end class EnterAction
	

}
